//
//  EPMReetweView.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/3/29.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMReetweView.h"
#import "EPMStatuesViewModel.h"
#import "EPMPhotoView.h"

@interface EPMReetweView()
@property (weak,nonatomic)  YYLabel* labContent;
@property (weak,nonatomic) EPMPhotoView* phototView;
@property (strong,nonatomic) MASConstraint* selfConstraint;

@end

@implementation EPMReetweView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.backgroundColor = [UIColor colorWithWhite:235.0/255 alpha:1.0];
//        self.backgroundColor = [UIColor redColor];
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    YYLabel* labContent = [YYLabel new];
    labContent.font = [UIFont systemFontOfSize:FONTSIZENORMAL];
    labContent.textColor = [UIColor darkGrayColor];
    _labContent = labContent;
    [self addSubview:labContent];
    labContent.numberOfLines = 0;
    labContent.preferredMaxLayoutWidth = screenWidth - 2*ViewMargine;
    
    EPMPhotoView* photoView = [EPMPhotoView new];
    _phototView = photoView;
    [self addSubview:photoView];
    //布局
    [labContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.offset(ViewMargine);
        make.width.mas_equalTo(screenWidth - 2*ViewMargine);
    }];
    [photoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.offset(ViewMargine);
        make.top.equalTo(labContent.mas_bottom).offset(ViewMargine);
    }];
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
      _selfConstraint = make.bottom.equalTo(photoView.mas_bottom).offset(ViewMargine);
    }];
    
}

- (void)setStatuesModel:(EPMStatuesViewModel *)statuesModel
{
    _statuesModel = statuesModel;
//    self.labContent.text = statuesModel.homeModel.retweeted_status.text;
    self.labContent.attributedText = statuesModel.reweetAttr;
    [_selfConstraint deactivate];
    if(statuesModel.homeModel.retweeted_status.pic_urls.count <= 0){
        _phototView.hidden = YES;
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            _selfConstraint = make.bottom.equalTo(_labContent).offset(ViewMargine);
        }];
        
    }else{
        _phototView.hidden = NO;
        self.phototView.modelList = statuesModel.homeModel.retweeted_status.pic_urls;
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            _selfConstraint = make.bottom.equalTo(_phototView).offset(ViewMargine);
        }];
    }
    
}

@end
